package com.grain.security.rbac.init;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

public abstract class AbstractDataInitializer implements DataInitializer{

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    @Transactional
    public void init() throws Exception {
        if (isNeedInit()) {
            logger.info("使用" + getClass().getSimpleName() + "初始化数据");
            doInit();
            logger.info("使用" + getClass().getSimpleName() + "初始化数据完毕");
        }
    }

    protected abstract void doInit();

    protected abstract boolean isNeedInit();
}
